package com.znsb.msfq.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.znsb.msfq.R;
import com.znsb.msfq.bean.CollectBean;
import com.znsb.msfq.utils.ImageLoader;
import com.znsb.msfq.utils.OnItemClickListener;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

import static com.znsb.msfq.app.ZnsbApp.mContext;


/**
 * @name：
 * @author： 孙科技
 * @phone： 13308334117
 * @createTime： 2017/2/10
 * @modifyTime： 2017/2/10
 * @explain：
 */

public class MyCollectRVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<CollectBean.DataListBean> dataList;
    private Context context;


    public MyCollectRVAdapter(Context context, List<CollectBean.DataListBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    public void updateList(List<CollectBean.DataListBean> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(mContext).inflate(R.layout.item_collect_view, parent, false);
        return new MyHolder(layout);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof MyHolder) {
            ((MyHolder) holder).collectTvName.setText(dataList.get(position).getTitle() + "");
            ((MyHolder) holder).collectTvPrice.setText("￥" + dataList.get(position).getPrice() + "");

            ((MyHolder) holder).collectTvShopname.setText(dataList.get(position).getSourceName() + "");
            ImageLoader.imageLoder(((MyHolder) holder).collectImgHead, dataList.get(position).getLogo() + "");
            ImageLoader.imageCircleLoder(((MyHolder) holder).collectImgShopname, dataList.get(position).getSourceLogo());
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(holder.itemView, position);
                }
            });
        }
    }

    class MyHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.collect_img_head)
        ImageView collectImgHead;
        @Bind(R.id.collect_tv_name)
        TextView collectTvName;
        @Bind(R.id.collect_tv_content)
        TextView collectTvContent;
        @Bind(R.id.collect_tv_price)
        TextView collectTvPrice;
        @Bind(R.id.collect_tv_shopname)
        TextView collectTvShopname;
        @Bind(R.id.collect_lin_layout1)
        LinearLayout collectLinLayout1;
        @Bind(R.id.collect_img_shopname)
        ImageView collectImgShopname;

        public MyHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
